/**
 * Created by nolan on 15/11/25.
 */
angular.module('sbAdminApp')
    .service('settlementresultService',['$http','httpResource',  function ($http, httpResource) {
        //delete $http.defaults.headers.common['X-Requested-With'];
    	var func="sc/rpt/settlement";
        
        this.search1 = function (sresult, pageno, itempersize) {
        	var name=null; var  status=null;  var category=null;  var type=null;
        	if(sresult!=null && sresult!=undefined ){
            	if(sresult.settlementTargetName!=undefined){
             	 	name=sresult.settlementTargetName;
             	  }
            	if(sresult.settlementStatus!=undefined){
            		status=sresult.settlementStatus;
             	  }
            	if(sresult.settlementCategory!=undefined){
            		category=sresult.settlementCategory;
             	  }
            	if(sresult.saleType!=undefined){
            		type=sresult.saleType;
             	  }
        	}
       	    return  $http({
	             url: func+'/result',
	             method: 'post',
	             params: {
		            	  settlementTargetName: name,
		            	  settlementStatus: status ,
		            	  settlementCategory: category,
		            	  saleType: type,
		            	  pageNo: pageno,
	          	          pageSize: itempersize
	          	       }
             });
        };
        
        this.statements=function (ids) {
    	    return  $http({
	             url: func+'/statements',
	             method: 'post',
	             params: {
	            	 ids: ids 
	          	      }
            });
        };
        
 
        
        this.export1=function (sresult,pageno, itempersize,currentPage) {
        	var name=null; var  status=null;  var category=null;  var type=null;
        	if(sresult!=null && sresult!=undefined ){
            	if(sresult.settlementTargetName!=undefined){
             	 	name=sresult.settlementTargetName;
             	  }
            	if(sresult.settlementStatus!=undefined){
            		status=sresult.settlementStatus;
             	  }
            	if(sresult.settlementCategory!=undefined){
            		category=sresult.settlementCategory;
             	  }
            	if(sresult.saleType!=undefined){
            		type=sresult.saleType;
             	  }
        	}
     	   $http({
               url: func+'/export',
               method: 'post',
               params: {
            	        settlementTargetName: name,
	            	    settlementStatus: status ,
	            	    settlementCategory: category,
	            	    saleType: type,
            	        pageNo: pageno,
            	        pageSize: itempersize,
            	        currentPage:currentPage
            	       },
               responseType: 'arraybuffer'
           }).success(function (data, status, headers) {
               var type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
               saveAs(new Blob([data], { type: type }), decodeURI(headers()["x-filename"]));  // 中文乱码
           }).error(function (data, status) {
               alert("导出失败!");
           });
        };
        
        
        this.reSettlement = function (sresult) {
       	    return  $http({
	             url: func+'/reSettlement',
	             method: 'post',
	             params: { 
		            	      id: sresult.id,
		            	      settlementTargetId: sresult.settlementTargetId,
		            	      settlementTargetName: sresult.settlementTargetName ,
		            	      feeType: sresult.feeType,
		            	      settlementTotalSum: sresult.settlementTotalSum,
		            	      settlementStatus: sresult.settlementStatus,
		            	      settlementType: sresult.settlementType,
		            	      settlementCategory: sresult.settlementCategory,
		            	      saleType: sresult.saleType ,
		            	      sbt: sresult.settlementBeginTime,
	 	            	      set: sresult.settlementEndTime,
		            	      ct: sresult.createTime 
	            	     }
	       	 
	          });
        };
        
        
    }]);